#include "Main_Menu.h"
#include <fstream>

using namespace CinePerfil;

System::Void Main_Menu::save_accounts_file()
{
	ofstream accounts_file;
	int aux;

	accounts_file.open("Accounts.bin");

	for(unsigned int k=0; k<accounts->size(); k++)
	{
		if (k != 0)
		{
			accounts_file << endl;
		}
		Account a = Account(accounts->data()[k]);
		
		accounts_file << a.get_username() << endl;
		accounts_file << a.get_password() << endl;
		aux = a.get_favorite_genres().size();
		accounts_file << aux << endl;
		for (int i=0; i<aux; i++)
		{
			accounts_file << a.get_favorite_genres()[i] << endl;
		}
		aux = a.get_series_to_follow().size();
		accounts_file << aux;
		for (int i=0; i<aux; i++)
		{
			accounts_file << endl << a.get_series_to_follow()[i];
		}
	}
	accounts_file.close();
}
System::Void Main_Menu::MM_accountManagementButton_Click(System::Object^  sender, System::EventArgs^  e) 
{
	Account_Management_Menu^ amm = gcnew Account_Management_Menu(account,database);
	this->Hide();
	amm->ShowDialog(this);
}
System::Void Main_Menu::MM_onClosed(System::Object^  sender, System::Windows::Forms::FormClosedEventArgs^  e)
{
	save_accounts_file();
}
System::Void Main_Menu::MM_searchButton_Click(System::Object^  sender, System::EventArgs^  e)
{
	Search_Window^ sw = gcnew Search_Window(database);
	this->Hide();
	sw->ShowDialog(this);
}

System::Void Main_Menu::MM_See_Last_ReleasesButton_Click(System::Object^  sender, System::EventArgs^  e) 
{
	Last_Releases_Window^ lrw = gcnew Last_Releases_Window(account,database);
	this->Hide();
	lrw->ShowDialog(this);
}